@echo off
REM Build script for Snake game (LAN version) for Visual Studio 2022
@echo off
setlocal

echo Building Snake game (LAN version)...
echo.

REM Check if running in Visual Studio Developer Command Prompt
where cl >nul 2>nul
if %errorlevel% neq 0 (
    echo Error: cl.exe compiler not found
    echo Please run this script in Visual Studio Developer Command Prompt
    echo Or launch "x64 Native Tools Command Prompt for VS 2022" from Start menu
    pause
    exit /b 1
)

REM Check SFML environment variable
if "%SFML_ROOT%"=="" (
    echo Warning: SFML_ROOT environment variable not set
    echo Please set SFML_ROOT to point to your SFML installation directory
    echo Example: set SFML_ROOT=C:\SFML
    echo.
)

REM Set include and library directories
set INCLUDE_DIR=%SFML_ROOT%\include
set LIB_DIR=%SFML_ROOT%\lib

if not exist "%INCLUDE_DIR%" (
    echo Warning: SFML include directory does not exist: %INCLUDE_DIR%
)

if not exist "%LIB_DIR%" (
    echo Warning: SFML library directory does not exist: %LIB_DIR%
)

echo Compiling...
cl /EHsc /Fe:snake.exe snake1\main.cpp snake1\snake.cpp snake1\game.cpp snake1\food.cpp snake1\constants.cpp /I"%INCLUDE_DIR%" /link /LIBPATH:"%LIB_DIR%" sfml-graphics.lib sfml-window.lib sfml-system.lib sfml-network.lib

if %errorlevel% equ 0 (
    echo.
    echo Build successful! Generated file: snake.exe
    echo.
    echo Usage instructions:
    echo 1. Make sure SFML library (Simple and Fast Multimedia Library) is installed
    echo 2. Run snake.exe to start the game
    echo 3. Choose [Single Player Mode] or [LAN Mode]
    echo 4. In LAN mode:
    echo    - One player selects [Create Room]
    echo    - Another player enters the host IP address and selects [Join Room]
    echo 5. Use WASD keys to control the snake
    echo.
) else (
    echo.
    echo Build failed!
    echo Possible reasons:
    echo 1. SFML library not installed
    echo 2. SFML library path configured incorrectly
    echo 3. Not running in Visual Studio Developer Command Prompt
    echo.
    echo SFML installation guide:
    echo 1. Download SFML for Visual Studio from https://www.sfml-dev.org/download.php
    echo 2. Extract to an appropriate location
    echo 3. Set SFML_ROOT environment variable to point to the extraction directory
    echo.
)

pause